1. Field of the Invention
The present invention relates to the field of data processing. More particularly, the present invention relates to a data processing apparatus and method for performing a shift-round-and-accumulate operation.
2. Description of the Prior Art
A data processing apparatus may perform an operation in which a data value is shifted to the left or right by a given number of bit positions and then added to an accumulate value. The result of the addition may be used as the accumulate value for a subsequent shift-and-accumulate operation. In this way, a sequence of different input values can be added together with the shift operation aligning successive input values with the accumulated value.
After shifting a value, it may be desirable to round the shifted value. For example, right shifting a binary value X by n bit positions to generate a shifted value y is functionally equivalent to dividing X by 2n and rounding down to the nearest integer less than X/2n. However, if the actual value of X/2n lies closer to y+1 than y, then it may sometimes be preferable to obtain the result y+1. Therefore, depending on the value of X/2n and the preferred rounding technique, the shifted value y may optionally be incremented to round the shifted value y to the value y+1. There may also be other reasons why rounding is desired. Typically, rounding is performed by adding a rounding value of 1 to the shift result.
If one wishes to perform an operation including a shift, an addition of the shifted value to the accumulate value, and a rounding operation, this would typically require the execution of several different instructions over three processing cycles: one cycle to perform the shift, one cycle to perform the rounding and one cycle to perform the accumulation. The present invention seeks to make this operation more efficient.